package com.djx.entity.access;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

//不能用@Data注解 不然会栈溢出 因为toString()。。。
@Entity
@Getter
@Setter
@Table(name = "t_role")
@NoArgsConstructor
public class Role implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    /**
     * 角色id
     */
    @Column(name = "id")
    private String id;

    /**
     * 角色名称
     */
    @Column(name = "role_name")
    private String roleName;

    /**
     * 角色描述
     */
    @Column(name = "role_description")
    private String roleDescription;

    /**
     * 最后操作时间
     */
    @Column(name = "modify_time")
    private Date modifyTime;

    /**
     * 是否删除 0 正常 1 删除
     */
    @Column(name = "is_delete")
    private Integer isDelete;


    @JsonIgnore
    @ManyToMany(mappedBy="roles")  //不维护中间表
    private Set<User> users = new HashSet<User>(0);//角色与用户   多对多

    /**
     * 角色与权限 多对多
     */

    @ManyToMany
    @JoinTable(name="t_role_permission",
            joinColumns={@JoinColumn(name="role_id",referencedColumnName="id")},
            inverseJoinColumns={@JoinColumn(name="permission_id",referencedColumnName="id")})
    private Set<Permission> permissions = new HashSet<Permission>(0);//角色与模块  多对多

}
